<template>
  <div
    class="component-pc-course__card new-card-item"
    @click="toPath(detail.id)"
  >
    <div class="new-card-left">
        <img v-lazy="detail.mainDiagram" :key="detail.mainDiagram" alt="">
    </div>
    <div class="new-card-right">
        <div class="title">
            {{detail.title}}
        </div>
        <div class="author">
            <span>{{detail.author}}</span><span style="margin-left:14px;">{{formatDate(detail.publishTime,1)}}</span>
        </div>
        <div class="profiles">
            {{getSimpleText(detail.introduce)}}
        </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  props: ["detail"],
  components: {},
  data() {
    return {
    };
  },
  computed: {
  },
  watch: {},
  filter:{
    
  },
  methods: {
    //   html剔除富文本标签，留下第一段纯文本
    getSimpleText(html){
      let re1 = new RegExp("<.+?>","g");//匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
      let msg = html.replace(re1,'');//执行替换成空字符
      let msg2 = msg.split('=');
      let msg3 = msg2.filter((i,x)=>i != '')[0]
      return msg3;
    },
    formatDate(time,type){
      // console.log(time)
      
      var time = new Date(time);
      
      var y = time.getFullYear();
      var m = time.getMonth()+1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      var add0 = (m)=>{
        return m<10?'0'+m:m;
      }
      if(type === 1){
        return y+'-'+add0(m)+'-'+add0(d);
      }else if(type === 2){
        return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
      }else if(type === 3){
        return add0(h)+':'+add0(mm)+':'+add0(s);
      }
      
    },
    toPath(id) {
      this.$router.push({
        path: "/information-detail",
        query: {
          id
        }
      });
    },
    
  },
  created() {
    // console.log("=============",this.detail);
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.component-pc-course__card {
    
}
.new-card-item{
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    padding: 25px;
    width: 580px;
    height: 200px;
    background-color: #ffffff;
    border-radius: 4px;
    margin-bottom: 42px;
    margin-left: 10px;
    margin-right: 10px;
    display: flex;
    justify-content: space-between;
    .new-card-left{
        width: 220px;
        // height: 150px;
        height: 146px;
        background-color: #5b96ff;
        border-radius: 4px;
        overflow: hidden;
        img{
            width: 100%;
            height: 100%;
            display: block;
        }
    }
    .new-card-right{
        width: 290px;
        height: 150px;
        // background-color: #5b96ff;
        .title{
            font-size: 16px;
            color: #4a4b4d;
            font-weight: bold;
            line-height: 24px;
            display: -webkit-box;
            -webkit-line-clamp:2;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
            height: 48px;
        }
        .author{
            margin:10px 0;
            font-size: 14px;
            font-weight: bold;
            line-height: 24px;
            color:#9a9da0;
        }
        .profiles{
            font-size: 12px;
            font-weight: bold;
            line-height: 20px;
            color: #abaeb3;
            display: -webkit-box;
            -webkit-line-clamp:3;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
            height: 60px;
        }
    }
}
</style>
<style lang="scss">
.component-pc-course__card {
}
</style>
